<template>
  <div class="app-container">

      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="楼盘名称" prop="housesName">
          <el-input v-model="form.housesName" placeholder="请输入楼盘名称" />
        </el-form-item>
        <el-form-item label="建筑面积" prop="housesArea">
          <el-input v-model="form.housesArea" placeholder="请输入建筑面积" />
        </el-form-item>
        <el-form-item label="容积率" prop="housesVolume">
          <el-input v-model="form.housesVolume" placeholder="请输入容积率" />
        </el-form-item>
        <el-form-item label="得房率" prop="housesGain">
          <el-input v-model="form.housesGain" placeholder="请输入得房率" />
        </el-form-item>
        <el-form-item label="绿化率" prop="housesAfforest">
          <el-input v-model="form.housesAfforest" placeholder="请输入绿化率" />
        </el-form-item>
        <el-form-item label="楼栋数" prop="housesNum">
          <el-input v-model="form.housesNum" placeholder="请输入楼栋数" />
        </el-form-item>
        <el-form-item label="开发商" prop="developers">
          <el-input v-model="form.developers" placeholder="请输入开发商" />
        </el-form-item>
        <el-form-item label="物业管理" prop="housesReal">
          <el-input v-model="form.housesReal" placeholder="请输入物业管理" />
        </el-form-item>
        <el-form-item label="楼盘简介" prop="mark">
          <el-input v-model="form.mark" placeholder="请输入楼盘简介" />
        </el-form-item>
        <el-form-item label="楼盘地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入楼盘地址" />
        </el-form-item>
        <el-form-item label="省份" prop="provinceId">
          <el-input v-model="form.provinceId" placeholder="请输入省份" />
        </el-form-item>
        <el-form-item label="市区" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入市区" />
        </el-form-item>
        <el-form-item label="县城" prop="countyId">
          <el-input v-model="form.countyId" placeholder="请输入县城" />
        </el-form-item>
        <el-form-item label="社区类型" prop="communityTypes">
          <el-input v-model="form.communityTypes" placeholder="请输入社区类型" />
        </el-form-item>
        <el-form-item label="物业类型" prop="realTypes">
          <el-input v-model="form.realTypes" placeholder="请输入物业类型" />
        </el-form-item>
        <el-form-item label="交通情况" prop="traffic">
          <el-input v-model="form.traffic" placeholder="请输入交通情况" />
        </el-form-item>
        <el-form-item label="删除标识 0：未删除，1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识 0：未删除，1：删除" />
        </el-form-item>
        <el-form-item label="常见用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入常见用户ID" />
        </el-form-item>
        <el-form-item label="更新用户ID" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
  </div>
</template>

<script>
import { listPremises, getPremises, delPremises, addPremises, updatePremises } from "@/api/house/premises";

export default {
  name: "add",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 楼盘表格数据
      premisesList: [],
      // 弹出层标题
      title: "",
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        housesId: null,
        housesName: null,
        housesArea: null,
        housesVolume: null,
        housesGain: null,
        housesAfforest: null,
        housesNum: null,
        developers: null,
        housesReal: null,
        mark: null,
        address: null,
        provinceId: null,
        cityId: null,
        countyId: null,
        communityTypes: null,
        realTypes: null,
        traffic: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.housesId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加楼盘";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const housesId = row.housesId || this.ids
      getPremises(housesId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改楼盘";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.housesId != null) {
            updatePremises(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPremises(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    }

  }
};
</script>
